package com.zy.dao.impl;

import com.zy.dao.AddUserDao;
import com.zy.utils.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AddUserDaoImpl implements AddUserDao {

    @Override
    public boolean addUser(String username, String password, String role, double balance) {
        String sql = "INSERT INTO tb_user (username, password, user_type, balance) VALUES (?, ?, ?, ?)";
        try (Connection connection = JdbcUtil.getConnection();
             PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, password);
            preparedStatement.setInt(3, Integer.parseInt(role));
            preparedStatement.setDouble(4, balance);
            int rowsAffected = preparedStatement.executeUpdate();
            return rowsAffected > 0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
} 